<!-- 新增和编辑弹窗 -->
<template>
  <a-modal
    :width="800"
    :visible="visible"
    title="详情"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-descriptions bordered :column="2" size="default">
      <a-descriptions-item label="设备类型">卷帘设备</a-descriptions-item>
      <a-descriptions-item label="推送类型">{{ formatType }}</a-descriptions-item>
      <a-descriptions-item label="具体设备" :span="2">{{ form.recordIds }}</a-descriptions-item>
      <a-descriptions-item label="设备总数">{{ form.total }}</a-descriptions-item>
      <a-descriptions-item label="分发情况">{{ formatSendResult }}</a-descriptions-item>
      <a-descriptions-item label="推送成功数">{{ form.distributeSuccess }}</a-descriptions-item>
      <a-descriptions-item label="推送失败数">{{ form.distributeFail }}</a-descriptions-item>
      <a-descriptions-item label="推送模板id">{{ form.templateId }}</a-descriptions-item>
    </a-descriptions>
    <a-divider/>
    <a-collapse :active-key="['1']">
      <a-collapse-panel key="1" header="推送内容">
        <p>{{ form.templateContent }}</p>
      </a-collapse-panel>
    </a-collapse>
    <a-divider/>
    <a-collapse :active-key="['1']">
      <a-collapse-panel key="1" header="执行失败信息">
        <p>{{ form.failMsg }}</p>
      </a-collapse-panel>
    </a-collapse>
  </a-modal>
</template>

<script>
import { reactive, toRefs, watchEffect } from 'vue';

export default {
  name: 'DeviceRollershadesFirmwareCommandTemplateDistributeDetail',
  emits: ['update:visible'],
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 详情数据
    data: Object
  },
  setup(props, context) {
    const data = reactive({
      form: {}
    });

    const watch = watchEffect(() => {
      if (props.data) {
        data.form = Object.assign({}, props.data);
      }
    });

    const updateVisible = value => {
      context.emit('update:visible', value);
    };

    return {
      ...toRefs(data),
      watch,
      updateVisible
    };
  },
  computed : {
    formatType : function () {
      if (this.form.sceneDictate == 0) {
        return "推送时间到终端";
      } else if (this.form.sceneDictate == 4) {
        return "重启终端设备";
      } else if (this.form.sceneDictate == 5) {
        return "通知设备更新代码";
      } else if (this.form.sceneDictate == 6) {
        return "更新终端网关的握手间隔时间";
      } else if (this.form.sceneDictate == 7) {
        return "设置终端连接服务器的IP和端口";
      } else if (this.form.sceneDictate == 10) {
        return "设置终端服务器的域名和端口";
      } else if (this.form.sceneDictate == 24) {
        return "设置参数(全局配置和各种参数配置)"
      } else if (this.form.sceneDictate == 32) {
        return "读取设备时间";
      } else if (this.form.sceneDictate == 37) {
        return "读取终端网关的握手间隔时间";
      } else if (this.form.sceneDictate == 56) {
        return "读取参数配置";
      } else if (this.form.sceneDictate == 9991) {
        return "一键清除配置";
      } else if (this.form.sceneDictate == 34) {
        return "读取设备id和固件版本";
      } else if (this.form.sceneDictate == 9992) {
        return "设置参数(升降手动设置)";
      }
    },
    formatSendResult : function() {
      if (this.form.isSend == 0) {
        return '未分发';
      } else if (this.form.isSend == 1) {
        return '分发中';
      } else if (this.form.isSend == 2) {
        return '分发完成，未存在失败';
      } else if (this.form.isSend == 3) {
        return '分发完成，存在失败';
      } else {
        return '-';
      }
    }
  }
};
</script>

<style scoped></style>
